//学生验证
//用户名，需要前后端交互
	const inp=document.getElementById("input1");
	const search1=document.getElementById("search1");
	const label1=document.getElementById('label1');
	inp.onfocus=function(){
		search1.classList.add("y");
		search1.classList.remove('err');
		label1.classList.add('label_1')
	}
	inp.onblur=function(){
		if(this.value.length>=3 &&this.value.length<=12){
			search1.classList.add("y");
			search1.classList.remove('err');
		}else{
			search1.classList.add('err')
		}
	}
	
// 密码
const inp1=document.getElementById('pwd');
const search2=document.getElementById("search2");
const miMatishi=document.getElementsByClassName('miMatishi')
// console.log(miMatishi)
inp1.onfocus=function(){
	miMatishi[0].classList.add('miMatishi_1')
	search2.classList.add("y");
}
inp1.onblur=function(){
	miMatishi[0].classList.remove('miMatishi_1')
	search2.classList.add("y");
}
inp1.oninput=function(){
	const l=this.value.length
	// console.log(l)
	if(l>=8 && l<=14){
		const tishi=document.getElementsByClassName('mi_1')
		console.log(tishi[0]);
		tishi[0].classList.add('miMatish_2')
	}else{
		const tishi=document.getElementsByClassName('mi_1')
		tishi[0].classList.remove('miMatish_2');
	}
	var reg=/^\w{3,20}$/
	if(reg.test(this.value)){
		const tishi=document.getElementsByClassName('mi_2')
		// console.log(tishi[0]);
		tishi[0].classList.add('miMatish_2')
	}else{
		const tishi=document.getElementsByClassName('mi_2')
		// console.log(tishi[0]);
		tishi[0].classList.remove('miMatish_2');
	}
	var reg1=/[^~\x22]+/
	if(reg1.test(this.value)){
		const tishi=document.getElementsByClassName('mi_3')
		// console.log(tishi[0]);
		tishi[0].classList.add('miMatish_2')
	}else{
		const tishi=document.getElementsByClassName('mi_3')
		// console.log(tishi[0]);
		tishi[0].classList.remove('miMatish_2');
	}
}
// 手机号
	const inp3=document.getElementById("input3");
	const search3=document.getElementById("search3");
	const label2=document.getElementById('label2');
	inp3.onfocus=function(){
		search3.classList.add("y");
		search3.classList.remove('err');
		label2.classList.add('label_1')
	}
	var reg3=/^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$/
	inp3.onblur=function(){
		if(reg3.test(this.value)){
			search3.classList.add("y");
			search3.classList.remove('err');
		}else{
			search3.classList.add('err')
		}
	}
// 邮箱
	const inp4=document.getElementById("input4");
	const search4=document.getElementById("search4");
	const label3=document.getElementById('label3');
	inp4.onfocus=function(){
		search4.classList.add("y");
		search4.classList.remove('err');
		label3.classList.add('label_1')
	}
	var reg4=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
	inp4.onblur=function(){
		if(reg4.test(this.value)){
			search4.classList.add("y");
			search4.classList.remove('err');
		}else{
			search4.classList.add('err')
		}
	}
	const btn=document.querySelector('button')
	// btn.disabled='true'
	if(search4.style.borderColor==='rgb(255,205,0)'){
		btn.disabled='flase';	
	}
	
// 讲师验证
	const inp_j=document.getElementById("input1_j");
	const search1_j=document.getElementById("search1_j");
	const label1_j=document.getElementById('label1_j');
	inp_j.onfocus=function(){
		search1_j.classList.add("y_j");
		search1_j.classList.remove('err_j');
		label1_j.classList.add('label_1_j')
	}
	inp_j.onblur=function(){
		if(this.value.length>=3 && this.value.length<=12){
			search1_j.classList.add("y_j");
			search1_j.classList.remove('err_j');
		}else{
			search1_j.classList.add('err_j')
		}
	}
	
// 密码
const inp1_j=document.getElementById('pwd_j');
const search2_j=document.getElementById("search2_j");
const miMatishi_j=document.getElementsByClassName('miMatishi_j')
// console.log(miMatishi)
inp1_j.onfocus=function(){
	miMatishi_j[0].classList.add('miMatishi_1_j')
	search2_j.classList.add("y_j");
}
inp1_j.onblur=function(){
	miMatishi_j[0].classList.remove('miMatishi_1_j')
	search2_j.classList.add("y_j");
}
inp1_j.oninput=function(){
	const l=this.value.length
	// console.log(l)
	if(l>=8 && l<=14){
		const tishi_j=document.getElementsByClassName('mi_1_j')
		console.log(tishi_j[0]);
		tishi_j[0].classList.add('miMatish_2_j')
	}else{
		const tishi_j=document.getElementsByClassName('mi_1_j')
		tishi_j[0].classList.remove('miMatish_2_j');
	}
	var reg=/^\w{3,20}$/
	if(reg.test(this.value)){
		const tishi_j=document.getElementsByClassName('mi_2_j')
		console.log(tishi_j[0]);
		tishi_j[0].classList.add('miMatish_2_j')
	}else{
		const tishi_j=document.getElementsByClassName('mi_2_j')
		console.log(tishi_j[0]);
		tishi_j[0].classList.remove('miMatish_2_j');
	}
	var reg1=/[^~\x22]+/
	if(reg1.test(this.value)){
		const tishi_j=document.getElementsByClassName('mi_3_j')
		console.log(tishi_j[0]);
		tishi_j[0].classList.add('miMatish_2_j')
	}else{
		const tishi_j=document.getElementsByClassName('mi_3_j')
		console.log(tishi_j[0]);
		tishi_j[0].classList.remove('miMatish_2_j');
	}
}

// 手机号
	const inp3_j=document.getElementById("input3_j");
	const search3_j=document.getElementById("search3_j");
	const label2_j=document.getElementById('label2_j');
	inp3_j.onfocus=function(){
		search3_j.classList.add("y_j");
		search3_j.classList.remove('err_j');
		label2_j.classList.add('label_1_j')
	}
	var reg3=/^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$/
	inp3_j.onblur=function(){
		if(reg3.test(this.value)){
			search3_j.classList.add("y_j");
			search3_j.classList.remove('err_j');
		}else{
			search3_j.classList.add('err_j')
		}
	}
	
// 邮箱
	const inp4_j=document.getElementById("input4_j");
	const search4_j=document.getElementById("search4_j");
	const label3_j=document.getElementById('label3_j');
	inp4_j.onfocus=function(){
		search4_j.classList.add("y_j");
		search4_j.classList.remove('err_j');
		label3_j.classList.add('label_1_j')
	}
	var reg4=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
	inp4_j.onblur=function(){
		if(reg4.test(this.value)){
			search4_j.classList.add("y_j");
			search4_j.classList.remove('err_j');
		}else{
			search4_j.classList.add('err_j')
		}
	}
	// const btn=document.querySelector('button')
	// // btn.disabled='true'
	// if(search4.style.borderColor==='rgb(255,205,0)'){
	// 	btn.disabled='flase';	
	// }
	
	//学生注册AJAX请求
	const url='http://127.0.0.1:8080/user/reg'
	$('#tow1>div>a>button').click(function(){
		const uname=$('#input1').val()//用户名
		const upwd=$('#pwd').val()//密码
		const phone=$('#input3').val()//手机号
		const email=$('#input4').val()//邮箱
		//获取输入框中的值
		let data = `uname=${uname}&upwd=${upwd}&email=${email}&phone=${phone}`;
		let xhr=new XMLHttpRequest();
		xhr.open("POST",'/user/reg');
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
		xhr.onload = () => {
			
			let jsonObj=JSON.parse(xhr.responseText)
			console.log(jsonObj)
			if(jsonObj.code==200){
				window.location.href='login.html'
			}else if(jsonObj.code==418){
				alert('注册失败!')
			}
		};
		xhr.send(data);
	})
	
	//讲师注册AJAX请求
	const url1='http://127.0.0.1:8080/user/reg'
	$('#two2>div>a>button').click(function(){
		const uname=$('#input1_j').val()//用户名
		const upwd=$('#pwd_j').val()//密码
		const phone=$('#input3_j').val()//手机号
		const email=$('#input4_j').val()//邮箱
		//获取输入框中的值
		let data = `uname=${uname}&upwd=${upwd}&email=${email}&phone=${phone}`;
		let xhr=new XMLHttpRequest();
		xhr.open("POST",'/user/reg_tutor');
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
		xhr.onload = () => {
			let jsonObj=JSON.parse(xhr.responseText)
			if(jsonObj.code==200){
				window.location.href='login.html'
			}else if(jsonObj.code==418){
				alert('注册失败!')
			}
		};
		xhr.send(data);
	})
	
	